home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / archiver / repak2.zip / REPAK.PAS < prev   
Pascal/Delphi Source File  |  1988-10-05  |  6KB  |  278 lines

  1. (*
  2.  
  3.    Program   REPAK
  4.    Version   1.00
  5.    Author    Atkinson - Home Computer - 414-543-8929 - 154/666
  6.    Language  Turbo Pascal 4
  7.    Utilities Turbo Professional
  8.    Dos       PC-DOS 3.3
  9.    Purpose   To compress archives with newer method compression
  10.    Date      10/03/88
  11.    Disk      Two files are written - \arcstodo.$$$ and \deletes.$$$
  12.              One directory is created \temp.$$$
  13.  
  14.    History   10/03/88 - Created the program
  15.          10/04/88 - Added -r switch to unpak routine
  16.          10/05/88 - Recoded .$$$ deletion code
  17.  
  18.    Usage: REPAK file
  19.  
  20.           Where file is desired .ARC
  21.  
  22.           Ex: *.*, *.ARC, A*.ARC AB*.ARC etc...
  23.  
  24.           Full Ex : REPAK A*.ARC
  25.  
  26. *)
  27.  
  28. {$B+}
  29. {$D-}
  30. {$F-}
  31. {$I-}
  32. {$L-}
  33. {$M 16000,0,100000}
  34. {$N-}
  35. {$R-}
  36. {$S-}
  37. {$T-}
  38. {$V+}
  39.  
  40. program repak;
  41. uses    dos, tpstring, tpdos, tpcrt, tpint;
  42.  
  43. const
  44.     inthandle = 15;
  45. var
  46.     quit : boolean;
  47.     code, loop : integer;
  48.     drive, startdir, arcname, filename, xpak_fullname, pak_fullname: string;
  49.     ok : boolean;
  50.     tempfilename, arcsfound, filestodelete : text;
  51.     attr : word;
  52.     searchfor : searchrec;
  53.  
  54. procedure findfirstarchive;
  55. begin
  56.     attr := $3f;
  57.     findfirst(forceextension(paramstr(1),'ARC'), attr, searchfor);
  58.     ok := doserror = 0;
  59.     if ok
  60.     then
  61.       begin
  62.         writeln(arcsfound, fullpathname(searchfor.name));
  63.       end;
  64.  
  65. end;
  66.  
  67. procedure findrestarchive;
  68. label 100;
  69. begin
  70. 100:    findnext(searchfor);
  71.     ok := doserror = 0;
  72.     if ok
  73.     then
  74.       begin
  75.         writeln(arcsfound, fullpathname(searchfor.name));
  76.         searchfor.name := '';
  77.       end;
  78.     if ok then goto 100;
  79. end;
  80.  
  81. procedure firstfiletodelete;
  82. begin
  83.     attr := $3f;
  84.     findfirst('*.*', attr, searchfor);
  85.     ok := doserror = 0;
  86.     if ok
  87.     then
  88.       begin
  89.         if searchfor.name <> '.'
  90.         then
  91.           writeln(filestodelete, fullpathname(searchfor.name));
  92.       end;
  93.  
  94. end;
  95.  
  96. procedure restfilestodelete;
  97. label 100;
  98. begin
  99. 100:    findnext(searchfor);
  100.     ok := doserror = 0;
  101.     if ok
  102.     then
  103.       begin
  104.         if searchfor.name <> '..'
  105.         then
  106.           writeln(filestodelete, fullpathname(searchfor.name));
  107.       end;
  108.     if ok then goto 100;
  109. end;
  110.  
  111. procedure cleanup;
  112. begin
  113.     assign(filestodelete, '\deletes.$$$');
  114.         rewrite(filestodelete);
  115.     chdir('\temp.$$$');
  116.         firstfiletodelete;
  117.     restfilestodelete;
  118.     close(filestodelete);
  119.     reset(filestodelete);
  120.     writeln;
  121.     writeln('Delete work files pass...');
  122.     writeln;
  123.     while not eof(filestodelete) and (not quit) do
  124.     begin
  125.       readln(filestodelete, filename);
  126.       writeln(filename);
  127.       assign(tempfilename, filename);
  128.       erase(tempfilename);
  129.     end;
  130.     close(filestodelete);
  131.     if not eof(arcsfound)
  132.     then
  133.       begin
  134.         writeln;
  135.         write('Changing directory to ');
  136.         writeln(justpathname(paramstr(1)));
  137.             chdir(justpathname(paramstr(1)));
  138.       end;
  139. end;
  140.  
  141. procedure doarc;
  142. begin
  143.     reset(arcsfound);
  144.         while not eof(arcsfound) and (not quit) do
  145.     begin
  146.       writeln;
  147.       writeln('Get archive pass...');
  148.       readln(arcsfound, arcname);
  149.       writeln;
  150.       writeln('Next file to process : ' + arcname);
  151.       code := execdos(xpak_fullname + ' -r ' + arcname+' \temp.$$$', false, Nil);
  152.       writeln;
  153.       writeln('Unpak status...');
  154.       writeln;
  155.       writeln('DosError    : ', doserror);
  156.       writeln('Using       : ', stupcase(xpak_fullname));
  157.       writeln('On file     : ', arcname);
  158.       writeln;
  159.       writeln('Repak pass...');
  160.       code := execdos(pak_fullname + ' -a '+arcname+' \temp.$$$\*.*', false, Nil);
  161.       writeln;
  162.       writeln('Pak status...');
  163.       writeln;
  164.       writeln('DosError    : ', doserror);
  165.       writeln('Using       : ', stupcase(xpak_fullname));
  166.       writeln('On file     : ', arcname);
  167.       cleanup;
  168.     end;
  169.     close(arcsfound)
  170. end;
  171.  
  172. procedure new1b(bp : word); interrupt;
  173. var
  174.     regs : intregisters absolute bp;
  175. begin
  176.     quit := true;
  177.     chainint(regs, isr_array[inthandle].origaddr);
  178. end;
  179.  
  180. procedure checkforfiles;
  181. var
  182.     notok1, notok2, notok3 : boolean;
  183. begin
  184.     attr := $10;
  185.     findfirst('\temp.$$$', attr, searchfor);
  186.     notok1 := doserror = 0;
  187.     attr := $3f;
  188.     findfirst('\arcstodo.$$$', attr, searchfor);
  189.     notok2 := doserror = 0;
  190.     attr := $3f;
  191.     findfirst('\deletes.$$$', attr, searchfor);
  192.     notok3 := doserror = 0;
  193.     if notok1 or notok2 or notok3
  194.     then
  195.       begin
  196.         writeln;
  197.         writeln('\TEMP.$$$ - \DELETES.$$$ - \ARCSTODO.$$$');
  198.         writeln;
  199.         writeln('All of these items needed, please check root directory...');
  200.         halt;
  201.       end;
  202. end;
  203.  
  204. procedure showhow;
  205. begin
  206.     writeln('');
  207.         writeln('Usage:');
  208.         writeln('');
  209.         writeln('REPAK file');
  210.         writeln('');
  211.         writeln('Where file is desired .ARC');
  212.         writeln('');
  213.         writeln('Ex: *.*, *.ARC, A*.ARC AB*.ARC etc...');
  214.     chdir(startdir);
  215.     halt;
  216. end;
  217.  
  218. procedure findprograms;
  219. begin
  220.         if (existonpath('PKARC.EXE', pak_fullname))
  221.     and (existonpath('PKXARC.EXE', xpak_fullname))
  222.     then
  223.       exit
  224.     else
  225.           if (existonpath('PKPAK.EXE', pak_fullname))
  226.     and (existonpath('PKUNPAK.EXE', xpak_fullname))
  227.     then
  228.       exit
  229.     else
  230.           begin
  231.             writeln(' ');
  232.             writeln('PKware .EXE compression programs not found on path...');
  233.         writeln;
  234.         writeln('PKARC.EXE and PKXARC.EXE or PKPAK.EXE and PKUNPAK.EXE...');
  235.         halt;
  236.           end;
  237. end;
  238.  
  239. procedure main;
  240. begin
  241.     getdir(0, startdir);
  242.         chdir(justpathname(paramstr(1)));
  243.     if paramcount = 0 then showhow;
  244.     checkforfiles;
  245.     if initvector($1b, inthandle, @new1b) then {};
  246.     ok := false;
  247.     quit := false;
  248.     assign(arcsfound, '\arcstodo.$$$');
  249.     rewrite(arcsfound);
  250.     findfirstarchive;
  251.     findprograms;
  252.     if ok
  253.     then
  254.       begin
  255.             mkdir('\temp.$$$');
  256.             findrestarchive;
  257.             close(arcsfound);
  258.             doarc
  259.           end
  260.         else
  261.           begin
  262.             writeln(' ');
  263.             writeln('No .ARC files to process...')
  264.           end;
  265.     writeln;
  266.     writeln('REPAK Finished...');
  267.     assign(tempfilename, '\deletes.$$$');
  268.     erase(tempfilename);
  269.     erase(arcsfound);
  270.     chdir('\');
  271.     rmdir('temp.$$$');
  272.     chdir(startdir);
  273. end;
  274.  
  275. begin
  276.     main;
  277. end.
  278.